/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 * No deletion without permission, or be held responsible to law.
 * @author YDZ
 */
import { defHttp } from '/@/utils/http/axios';
import { useGlobSetting } from '/@/hooks/setting';
import { BasicModel, Page } from '../model/baseModel';
import { UploadFileParams } from '/#/axios';
import { UploadApiResult } from '../sys/upload';

const { ctxPath, adminPath } = useGlobSetting();

export interface PuBillVouch extends BasicModel<PuBillVouch> {
  djno?: string; // 单据号
  pkCorp?: string; // 公司主键
  venId?: string; // 供应商ID
  ddate?: string; // 单据日期
  itaxmoney?: number; // 价税合计
  itax?: number; // 税额
  imoney?: number; // 无税金额
  currtypename?: string; // 币种
  prtQty?: number; // 打印次数
  puBillVouchsList?: any[]; // 子表列表
}

export const puBillVouchList = (params?: PuBillVouch | any) =>
  defHttp.get<PuBillVouch>({ url: adminPath + '/srm/cw/billvouch/puBillVouch/list', params });

export const puBillVouchListData = (params?: PuBillVouch | any) =>
  defHttp.post<Page<PuBillVouch>>({
    url: adminPath + '/srm/cw/billvouch/puBillVouch/listData',
    params,
  });

export const puBillVouchForm = (params?: PuBillVouch | any) =>
  defHttp.get<PuBillVouch>({ url: adminPath + '/srm/cw/billvouch/puBillVouch/form', params });

export const puBillVouchSave = (params?: any, data?: PuBillVouch | any) =>
  defHttp.postJson<PuBillVouch>({
    url: adminPath + '/srm/cw/billvouch/puBillVouch/save',
    params,
    data,
  });

export const puBillVouchDelete = (params?: PuBillVouch | any) =>
  defHttp.get<PuBillVouch>({ url: adminPath + '/srm/cw/billvouch/puBillVouch/delete', params });

export const puBillVouchCalcMoney = (params?: PuBillVouch | any) =>
  defHttp.get<PuBillVouch>({ url: adminPath + '/srm/cw/billvouch/puBillVouch/calcMoney', params });

// 开票通知单发票识别

export const puBillVouchInvoice = (
  params: UploadFileParams,
  onUploadProgress: (progressEvent: ProgressEvent) => void,
  cancelToken?: any,
) =>
  defHttp.uploadFile<UploadApiResult>(
    {
      url: ctxPath + adminPath + '/srm/cw/billvouch/puBillVouch/invoice',
      onUploadProgress,
      cancelToken,
    },
    params,
  );
// 查询指定单据已上传的发票记录
export const puBillVouchInvoiceRecords = (params?: PuBillVouch | any) =>
  defHttp.get<PuBillVouch>({
    url: adminPath + '/srm/cw/billvouch/puBillVouch/invoiceRecords',
    params,
  });

// 删除指定的发票
export const puBillVouchDeleteInvoice = (params?: PuBillVouch | any) =>
  defHttp.post<Page<PuBillVouch>>({
    url: adminPath + '/srm/cw/billvouch/puBillVouch/deleteInvoice',
    params,
  });
// 验证上传的发票数总金额是否匹配单据金额
export const puBillVouchVerifyInvoice = (params?: PuBillVouch | any) =>
  defHttp.get<PuBillVouch>({
    url: adminPath + '/srm/cw/billvouch/puBillVouch/verifyInvoice',
    params,
  });

// /srm/cw/billvouch/puBillVouch/execMatch 执行匹配
export const puBillVouchExecMatch = (params?: PuBillVouch | any) =>
  defHttp.post<PuBillVouch>({
    url: adminPath + '/srm/cw/billvouch/puBillVouch/execMatch',
    params,
  });

// 暂存结果
export const puBillVouchTempSave = (params?: PuBillVouch | any) =>
  defHttp.postJson<PuBillVouch>({
    url: adminPath + '/srm/cw/billvouch/puBillVouch/tempSave',
    params,
  });
// /m8/a/srm/cw/billvouch/puBillVouch/submit 提交
export const puBillVouchSubmit = (params?: PuBillVouch | any) =>
  defHttp.postJson<PuBillVouch>({
    url: adminPath + '/srm/cw/billvouch/puBillVouch/submit',
    params,
  });
